# -*- coding: utf-8 -*-
# @Time    : 2023/2/7 16:41
# @Author  : kali
import re


def get_dict(*args, **kwargs):
    if not args and not kwargs:
        return {}
    if len(args) == 1 and not kwargs and isinstance(args[0], dict):
        return args[0]
    if kwargs and not args:
        return kwargs

    raise ValueError('neither a dict nor a **kwargs')


def read_chunk(file_name, chunk_size=20 * 1024 * 1024):
    with open(file_name, 'rb') as target_file:
        while True:
            chunk = target_file.read(chunk_size)
            if not chunk:
                break
            yield chunk


def get_snake_case(name, separator='_'):
    com = re.compile('((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))')
    return com.sub(r'{}\1'.format(separator), name).lower()
